package com.scedu.dao.impl;

import com.scedu.dao.StudentDao;
import com.scedu.entity.Student;
import com.scedu.utils.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class StudentDaoImpl implements StudentDao {
    @Override
    public List<Student> findAllStudent() {
        //获取sqlsession
        SqlSession sqlSession = MybatisUtil.getSqlSession();
        String sqlId="com.scedu.dao.StudentDao.findAllStudent";
        //执行sql语句，使用sqlSession类的方法
        List<Student> studentList = sqlSession.selectList(sqlId);
        //关闭sqlsession
        sqlSession.close();
        //返回查询结果List<Student>
        return studentList;
    }

    @Override
    public int insertStudent(Student student) {

        //获取sqlsession
        SqlSession sqlSession = MybatisUtil.getSqlSession();
        String sqlId="com.scedu.dao.StudentDao.insertStudent";
        //执行sql语句，使用sqlSession类的方法
        int insert = sqlSession.insert(sqlId, student);
        //提交事务
        sqlSession.commit();
        //关闭sqlsession
        sqlSession.close();
        //返回查询结果List<Student>
        return insert;
    }
}
